import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:ichinesereader/constants.dart';
import 'package:ichinesereader/controller/cache.dart';
import 'package:ichinesereader/controller/reports.dart';
import 'package:ichinesereader/utils/log.dart';
import 'package:ichinesereader/widgets/grids/testRecordGrid.dart';

class QuickReviewOverviewList extends StatefulWidget {
  @override
  _QuickReviewOverviewListState createState() =>
      _QuickReviewOverviewListState();
}

class _QuickReviewOverviewListState extends State<QuickReviewOverviewList> {
  final box = Hive.box('appconfig');
  final ReportsController controller = Get.find();
  String _classId = '';
  bool isTeacher = false;

  @override
  void initState() {
    isTeacher = box.get(CacheManagerKey['nanhairole'].toString()) ==
        Constants.NanhaiRole_Teacher;

    if (isTeacher) {
      _classId = box.get(CacheManagerKey['currentclass'].toString());
    }
    Future.delayed(Duration(milliseconds: 300), (() {
      controller.fetchLibraryRecords(_classId);
    }));

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    Log.debug('build quiz review list');

    return controller.obx(
      (data) {
        if (controller.quickReviewLibraryRecordItems.length > 0) {
          return TestDataRecordGrids(
              controller.quickReviewLibraryRecordItems, true, 'quickReview');
        } else {
          return Center(child: Text('No data'));
        }
      },
      onEmpty: Center(
        child: Text('No data'),
      ),
      // onLoading: Center(
      //     child: CircularProgressIndicator(
      //   backgroundColor: Get.theme.primaryColorDark,
      //   strokeWidth: 9.0,
      // )),
    );
  }
}
